
$(function () {
    var itemIndex = 0;
    var tabScroolTopArray = [0, 0, 0];  // 这块是三页面 每个page 都是从0开始 这个插件的第一页是从0开始的
    var dropload = $('.addhtmlwarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<a class="add_morelink">上拉加载更多</a>',
            domLoad: '  <a class="add_morelink">加载中...</a>',
            domNoData: '<a class="add_morelink">已无数据...</a> '
        },
        loadDownFn: function (me) {
            tabScroolTopArray[itemIndex]++;
            // 拼接HTML
            if(tabScroolTopArray[itemIndex]>=3){
                me.resetload();
                me.lock();
                me.noData();
                me.resetload();
                return;
            }
                $.ajax({
                    type: 'GET',
                    url: 'json/data.json',
                    data: { },
                    dataType: 'json',
                    success: function (data) {
                        var arrLen = data.data.length;
                        if (arrLen > 0) {
                          //加载内容
                          var orderList = '';
                          $(data.data).each(function (k, v) {
                            if(v.img_lis.length<=1){
                                orderList += '<li  class="them1">';
                                orderList += '<a href="'+v.href+'" class="lazy"><img src="'+v.img_lis[0]+'" alt=""></a>';
                                orderList += '<div class="infor">';
                                orderList += '<a href="##" class="name">'+v.title+'</a>';
                                orderList += '<div class="tex">';
                                orderList += ''+v.des+'';
                                orderList += '</div>';
                                orderList += '<div class="p">';
                                orderList += '<div class="flex1">';
                                orderList += '<a href="##">来自 硬件-显卡 资讯</a>';
                                orderList += '</div>';
                                orderList += '<div class="fr">';
                                orderList += '<span class="time">'+v.time+'</span> ';
                                orderList += '<span class="pl"><i class="icoimg"></i>'+v.comment+'</span>';
                                orderList += '</div>';
                                orderList += '</div>';
                                orderList += '</div>';
                                orderList += '</li>';
                            }else{
                                orderList += '<li>';
                                orderList += '<a href="##" class="name">'+v.title+'</a>';
                                orderList += '<div class="img_lis">';
                                for(var i=0;i<=v.img_lis.length-1;i++){
                                    orderList += '<a href="##" class="lazy"><img src="'+v.img_lis[i]+'" alt=""></a>';
                                }
                                orderList += '</div>';
                                orderList += '<div class="p">';
                                orderList += '<div class="flex1">';
                                orderList += '<a href="##">来自 硬件-显卡 资讯</a>';
                                orderList += ' </div>';
                                orderList += '<div class="fr">';
                                orderList += '   <span class="time">'+v.time+'</span> ';
                                orderList += '   <span class="pl"><i class="icoimg"></i>'+v.comment+'</span>';
                                orderList += '</div>';
                                orderList += '</div>';
                                orderList += '</li>';
                            }
                          })
                            // 如果没有数据
                        } else {
                            // 锁定
                            me.lock();
                            // 无数据
                            me.noData();
                        }
                        $(".addhtmlwarp .list").eq(itemIndex).find(" ul").append(orderList);
                        $(window).trigger('scroll');
                        me.resetload();    // 每次数据插入，必须重置
                    },
                    error: function (xhr, type) {
                        // 即使加载出错，也得重置
                        me.resetload();
                    }
                });
        }
    });
    $('.addhtmlwarp .switch_bt1 .a').on('click', function () {
        $(".addhtmlwarp .list").eq($(this).index()).show().siblings().hide()
        itemIndex = $(this).index();
        $(this).addClass('on').siblings().removeClass('on');
        dropload.unlock();
        dropload.noData(false);
        dropload.resetload();
    });
});
